package com.mujin.keji.collectionsystem.db.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.mujin.keji.collectionsystem.module.login.dto.UserDto;

import java.util.List;

import io.reactivex.Flowable;

/**
 * 登录操作
 */
@Dao
public interface UserDao {

    /**
     * 查询用户列表
     * @return
     */
    @Query("select * from t_user_info where username = (:username) order by id desc ")
    Flowable<List<UserDto>> findUserList(String username);

    /**lacl
     * 添加用户
     * @param userDtos 可变参数 可以多个
     */
    @Insert
    void addUser(UserDto...userDtos);

    @Query("delete from t_user_info ")
    void deleteAll();

    /**
     * 根据ID查询用户
     * @param ids 可以多个ID 查询多个用户
     */
    @Query("select * from t_user_info where id in (:ids)")
    List<UserDto> findUserById(Long[] ids);

    @Query("select * from t_user_info where username = (:username)")
    UserDto findUserByUserName(String username);

    /**
     * 更新用户
     * @param userDtos
     */
    @Update
    void updateUser(UserDto ... userDtos);

}
